package Collection存储学生对象并遍历;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo {
    public static void main(String[] args) {
        //创建collection集合对象
        Collection<Student> s = new ArrayList<Student>();

        //创建学生对象
        Student s1 = new Student("姜恒星", 30);
        Student s2 = new Student("姜恒", 30);
        Student s3 = new Student("姜", 30);

        //把学生添加到集合
        s.add(s1);
        s.add(s2);
        s.add(s3);

        //遍历集合（迭代器方式）
        Iterator<Student> it = s.iterator();

        while (it.hasNext()) {
            Student stu = it.next();
            System.out.println(stu.getName() + "," + stu.getAge() + ",");
        }
    }
}